package db;

import java.sql.*;

public class MysqlDB {
    public Connection getConn()throws SQLException {
        Connection conn=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bookstore?useUnicode=true&characterEncoding=utf-8","root","000000");


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public void closeAll(Connection conn, PreparedStatement ps,ResultSet rs)throws SQLException{
        if(conn!=null&conn.isClosed()){
            conn.close();
        }
        if(ps!=null){
            ps.close();
        }
        if (rs!=null){
            rs.close();
        }
    }

    public static void main(String[] args) {
        MysqlDB db=new MysqlDB();
        try {
            System.out.println(db.getConn().isClosed());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
